package com.wushi.lenovo.asia5b.app_ui.other.dialog;

import android.content.Context;
import android.support.annotation.StringRes;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.mvp.base.BaseDialog;
import com.mvp.helper.WCallBack;
import com.mvp.utils.ResString;
import com.wushi.lenovo.asia5b.R;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by zhangyuncai on 2018/12/11.
 * 确认取消框
 */
public class CancelSureDialog extends BaseDialog implements View.OnClickListener {
    @BindView(R.id.tv_cancelsure_cancel)
    TextView tv_cancelsure_cancel;
    @BindView(R.id.tv_cancelsure_sure)
    TextView tv_cancelsure_sure;
    @BindView(R.id.tv_cancelsure_content)
    TextView tv_cancelsure_content;
    @BindView(R.id.iv_cancelsure_ok)
    ImageView iv_cancelsure_ok;
    @BindView(R.id.iv_logout_icon)
    ImageView iv_logout_icon;
    @BindView(R.id.tv_cancelsure_titlename)
    TextView tv_cancelsure_titlename;
    private String sure;
    private String cancel;
    private String content;
    private String titleName;
    private boolean isVisibleIcon = false;
    private boolean isVisibleTitleName = false;


    public CancelSureDialog(Context context) {
        super(context);
    }

    public CancelSureDialog(Context context, @StringRes int sure, @StringRes int cancel, @StringRes int content, WCallBack callBack) {
        super(context);
        super.callBack = callBack;
        this.sure = ResString.get(sure);
        this.cancel = ResString.get(cancel);
        this.content = ResString.get(content);
    }

    public static class Builder {
        CancelSureDialog cancelSureDialog = null;
        private Context context;

        public Builder(Context context) {
            this.context = context;
            cancelSureDialog = new CancelSureDialog(context);
        }

        public Builder setLeftContent(@StringRes int leftContent) {
            cancelSureDialog.sure = ResString.get(leftContent);
            return this;
        }

        public Builder setLeftContent(String leftContent) {
            cancelSureDialog.sure = leftContent;
            return this;
        }

        public Builder setRightContent(@StringRes int rightContent) {
            cancelSureDialog.cancel = ResString.get(rightContent);
            return this;
        }

        public Builder setRightContent(String rightContent) {
            cancelSureDialog.cancel = rightContent;
            return this;
        }


        public Builder setContent(@StringRes int content) {
            cancelSureDialog.content = ResString.get(content);
            return this;
        }

        public Builder setContent(String content) {
            cancelSureDialog.content = content;
            return this;
        }

        public Builder setTitleName(@StringRes int titleName) {
            cancelSureDialog.titleName = ResString.get(titleName);
            return this;
        }

        public Builder setTitleName(String titleName) {
            cancelSureDialog.titleName = titleName;
            return this;
        }

        public Builder setVisibleIcon(boolean isVisibleIcon) {
            cancelSureDialog.isVisibleIcon = isVisibleIcon;
            return this;
        }

        public Builder setVisibleTitleName(boolean isVisibleTitleName) {
            cancelSureDialog.isVisibleTitleName = isVisibleTitleName;
            return this;
        }

        public Builder setCallBack(WCallBack callBack) {
            cancelSureDialog.callBack = callBack;
            return this;
        }

        public CancelSureDialog build() {
            return cancelSureDialog;
        }
    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_cancelsure;
    }

    @Override
    protected void initView() {
        tv_cancelsure_cancel.setText(cancel);
        tv_cancelsure_sure.setText(sure);
        tv_cancelsure_content.setText(content);
        if (!TextUtils.isEmpty(titleName)) {
            tv_cancelsure_titlename.setText(titleName);
        }
        tv_cancelsure_titlename.setVisibility(isVisibleTitleName ? View.VISIBLE : View.GONE);
        iv_logout_icon.setVisibility(isVisibleIcon ? View.VISIBLE : View.GONE);
    }

    @Override
    protected void initListener() {

    }

    @Override
    protected int getWidthStyle() {
        return getScreenWidth(0.8f);
    }

    @Override
    protected int getGravity() {
        return Gravity.CENTER;
    }

    @OnClick({R.id.tv_cancelsure_sure, R.id.tv_cancelsure_cancel
            , R.id.iv_cancelsure_ok})
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_cancelsure_sure:
                dismiss();
                if (callBack != null) {
                    callBack.callback(null);
                }
                break;
            case R.id.iv_cancelsure_ok:
            case R.id.tv_cancelsure_cancel:
                dismiss();
                break;
        }

    }
}
